﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.IBLL;
using HZ.Supervise.Model;
using HZ.Supervise.Model.Enum;
using HZ.Supervise.Model.View;

namespace HZ.Supervise.Web.Secondphase.Statistics
{
     
    public partial class CompanyResponse24HourByCompany : BasePage
    { 
        IExecuteContext iec = HZ.Supervise.BLLFactory.ExecuteContext();

        public CompanyResponse24HourByCompany()
        {

        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager_CompanyPS_PageChanged(object sender, EventArgs e)
        {
            //AspNetPager_CompanyPS.CurrentPageIndex = 1; 
            BindData();

        }

        /// <summary>
        /// 绑定数据
        /// modify  by张雄  2011.5.4
        /// </summary>
        public void BindData()
        {
            SuperviseQuery vs = new SuperviseQuery();
            vs = Queryby();
            HZ.Supervise.Model.View.ProcureCatalog mPro = iec.GetProcureCatalogByID(vs.ProcureCatalogID);

            lblTitle.Text = string.Format(@"流水号：{3}； 通用名：{0}； 剂型：{1}； 包装：{2}；生产企业：{4}；", mPro.ProductName, mPro.MedicineModelName, mPro.Pack, mPro.ProcureCatalogID, mPro.CompanyName_SC);
          
            int t = 0;
            System.Data.DataTable dt = iec.Get24HourByCompany (vs, this.AspNetPager_CompanyPS.CurrentPageIndex, AspNetPager_CompanyPS.PageSize, out t);
            AspNetPager_CompanyPS.RecordCount = t;

            this.gvwPSLInfo.PageSize = AspNetPager_CompanyPS.PageSize;
            this.gvwPSLInfo.DataSource = dt;
            this.gvwPSLInfo.DataBind();



        }
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager_CompanyPS.CurrentPageIndex = 1;
        }
        /// <summary>
        /// 分页  
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void CompanyPSL_PS_PageChanged(object sender, EventArgs e)
        {
            BindData();

        }



        /// <summary>
        /// 导出 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnExcel_Click(object sender, EventArgs e)
        {
            SuperviseQuery vs = new SuperviseQuery();
            vs = Queryby();
            int t = 0;
            System.Data.DataTable dt = iec.Get24HourByCompany(vs, 1, 0, out t);
            ExportFile.Instance.ExportData(dt, gvwPSLInfo, this.Page);
        }



        /// <summary>
        /// 查询条件
        /// </summary>
        /// <returns></returns>
        private SuperviseQuery Queryby()
        {
            SuperviseQuery vs = new SuperviseQuery();

            vs = (SuperviseQuery)Session[Request.QueryString["sesid"]];
            vs.CompanyID_PS = null;
            vs.CompanyName_PS = txtCompanyName_PS.Text.Trim();

            vs.SortFields = ddlSortFields.SelectedValue + " " + ddlSort.SelectedValue;
            return vs;
        }



        protected void gvwInfo_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            SuperviseQuery vs = new SuperviseQuery();
            vs = Queryby();
            string sessionId = Guid.NewGuid().ToString();
            Control cmdControl = e.CommandSource as Control;
            GridViewRow row = cmdControl.NamingContainer as GridViewRow;
            Session[sessionId] = vs;

            if (e.CommandName == "lbnCom")
            {
                LinkButton lbnR = (LinkButton)row.FindControl("lbnCom");
                vs.CompanyID_PS = lbnR.CommandArgument;
                vs.CompanyName_PS = row.Cells[2].Text;
                Response.Redirect("CompanyResponse24HourByDetail.aspx?sesid=" + sessionId);

            }
        }
        protected void btnBack_Click(object sender, EventArgs e)
        {
            string url = "CompanyResponse24HourByProcureCatalog.aspx?sesid=" + Request.QueryString["sesid"];
            Response.Redirect(url);
 
        }
    }
}
